<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.adtech.adms.system.pojo.Topo"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script>

$().ready(function() {
	$.validator.setDefaults({
	submitHandler: function() { alert("submitted!"); }
});

	// validate the comment form when it is submitted

	// validate signup form on keyup and submit
	$("#form1").validate({
		rules: {
			"topo.nodeid": {
				required: true,
				minlength: 1,
				number:true,
			}
		},
		messages: {
			"topo.nodeid": {
				required: "拓扑标识",
				minlength: "拓扑标识为1-4位的数字",
				number:"拓扑标识为1-4位的数字",
			}
		},
		 showErrors: function(errorMap, errorList) {
			    
			    this.defaultShowErrors();
			  }
	});

	
});
</script>

<form id="form" class="hForm treeForm" action="">
<div style="border:1px solid #c2e2eb;height: 25px;">
<s:hidden name="topo.id" id="featureId"></s:hidden>
<s:hidden name="topo.parent.id"></s:hidden>
<s:if test="topo.id!=null">
				编辑模块
			</s:if>
			<s:else>
				新建模块
			</s:else>
</div>

	<div class="rowElem">
		<label>名称：</label>
		<s:textfield name="topo.name" cssClass="dialoginput"></s:textfield>
	</div>
	<div class="rowElem">
		<label>标识：</label>
		<s:textfield name="topo.nodeid" cssClass="dialoginput"></s:textfield>
	</div>
	<div class="rowElem">
		<label>路径：</label>
		<s:textfield name="topo.path" cssClass="dialoginput"></s:textfield>
	</div>
	<div class="rowElem">
		<label>全路径：</label>
		<s:label name="topo.fullPath" cssClass="dialoginput"></s:label>
	</div>
		<div class="topo_button">
			<a href="#" class="button" tabindex="-1"><input id="save_button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" value="保存"></a>
		</div>
</form>

<script>
$(document).ready(function(){
	var treeObject = $.fn.zTree.getZTreeObj("featureTree");
	var container = $('div.container');
	// validate the form when it is submitted
	var validator = $("#form").validate({
		submitHandler: function(form) {
			return false;
		},
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		rules: {
		     "topo.name":{
		      required: true, 
		      maxlength:100
		     }
	    },
	    messages:{
	    	"topo.name":{
	    		required: "模块名称是必需的"
	    	}
	    }
	});
	
	$("#save_button").bind('click',function(){
		if(!validator.form()){
			return false;
		}
		
		
		selectedNode =	treeObject.getSelectedNodes()[0];
			$.adAjax({
			type : "post",
			url : baserUrl+'topo/save',
			data:$('#form').serialize(),
			success : function(){
				if(selectedNode == null){
					$("#featureTree").zTree(setting);
				}else{
					
					var nodes=treeObject.getNodes();
					if(nodes.length<=0||$("#feature_root").attr("checked")){
						document.location.href= baserUrl+ "/feature/frame";
						return;
					}
	                selectedNode.isParent =true;
					treeObject.updateNode(selectedNode, true);                                
					<s:if test="%{topo.id!=null}">
						treeObject.reAsyncChildNodes(selectedNode.parentNode, "refresh");
					</s:if>
					<s:else>
						treeObject.reAsyncChildNodes(selectedNode, "refresh");
					</s:else>
					
					treeObject.selectNode (selectedNode,true);
					$('#detail_panel').load(baserUrl+'/topo/detail?id='+ selectedNode.id);
				}
			}
		});
		
		return false;
	});
	
	/**
<s:if test="%{topo.id == null}">
	$('#parnet_name').text(treeObject.getSelectedNode().name);
	</s:if>
	**/
	$("#feature_root").bind('click',function(){
		if(this.checked){
			$('#parnet_text').hide();
		}else{
			$('#parnet_text').show();
		}
	});
	contentLayout();
});


function contentLayout(){
	$(".tempDiv").css("height",window.document.body.clientHeight-34-28);
	$(".content_c").css("height",window.document.body.clientHeight-$(".serverErrorContainer").height()-46-34-28);
	if($.browser.msie&&($.browser.version == "6.0")){
		$(".content_c").css("width",window.document.body.clientWidth-5);
	}
	//$(".serverErrorContainer").css("width",window.document.body.clientWidth);
}

$(window).resize(function(){
	$(".tempDiv").css("height",window.document.body.clientHeight-34-28);
	$(".content_c").css("height",window.document.body.clientHeight-$(".serverErrorContainer").height()-46-34-28);
	if($.browser.msie&&($.browser.version == "6.0")){
		$(".content_c").css("width",window.document.body.clientWidth-5);
	}
	$(".serverErrorContainer").css("width",window.document.body.clientWidth);
});
</script>